home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 71 / utl / rename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  2.4 KB  |  62 lines

  1. /* 
  2.  *  RENAME.C  by Mitch Trachtenberg         Cserv 73647,1447
  3.  *
  4.  *  Megamax C code to create rename.prg, a skeleton program that allows 
  5.  *  the renaming of a file "across directories"; that is, which
  6.  *  allows you to move a file into or out of a subdirectory without
  7.  *  having to copy it and then delete it. Frename(), below, is defined 
  8.  *  in osbind.h (from either Atari or Megamax) as:
  9.  *         #define Frename(a,b,c) gemdos(0x56,a,b,c)
  10.  *  This program accepts its arguments from the command line; if they are
  11.  *  not found in the command line (or if the program is invoked from the
  12.  *  GEM desktop) it prompts for them.
  13.  */
  14. #include "osbind.h"
  15. #include "stdio.h"
  16. #include "string.h"
  17. char current_pathname[100];
  18. char new_pathname[100];
  19. main(argc,argv)
  20. int argc;
  21. char **argv;
  22. {int retval;
  23.  char *current;
  24.  char *new;
  25.  char *cur_name_only;
  26.  if(argc<3)  /* the command line didn't contain all necessary arguments */
  27.    {current=current_pathname;              /* so get them from the user */
  28.     fputs("Current pathname: ",stdout); /* fputs doesn't append newline */
  29.     gets(current_pathname);              /* get first argument; current */
  30.     new=new_pathname;
  31.     fputs("New pathname: ",stdout);         /* get second argument; new */
  32.     gets(new_pathname);
  33.    }
  34.  else       /* at least two command line arguments, assume they're legal */
  35.    {current=argv[1];                   /* first argument becomes current */
  36.     new=argv[2];                          /* second argument becomes new */
  37.    }
  38.  
  39.  cur_name_only=rindex(current,'\\');   /* find last backslash in current */
  40.    /* because, if it exists, it precedes the filename part of the string */
  41.  
  42.  if(*(new+strlen(new)-1)=='\\')    /* if the new name given by user ends */
  43.                                 /* with a backslash, append the old name */
  44.   {if(cur_name_only)strcat(new,++cur_name_only);
  45.    else strcat(new,current);
  46.   }
  47.  
  48.  fputs("Now renaming \"",stdout);/* show user what you think you're doing */
  49.  fputs(current,stdout);
  50.  fputs("\" to \"",stdout);
  51.  fputs(new,stdout);
  52.  puts("\".");
  53.  retval=Frename(0,current,new);                      /* then try to do it */
  54.                                     /* and let user know how things went. */
  55.  if(retval<0)
  56.    {puts("Renaming failed. Check pathnames for validity.");
  57.     exit(2);
  58.    }
  59.  else puts("Renamed.");
  60.  exit(0);
  61. }
  62. əəəəəəəəəəəəəəəəəəəəəəəəəəəə